home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / amiga / asrc29k.lha / axlink.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  3.0 KB  |  155 lines

  1. #include <ctype.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "iface.h"
  5. #include "ax25.h"
  6. #include "ip.h"
  7. #include "timer.h"
  8.  
  9. #define iscallsign(c) ((isupper(c)) || (isdigit(c)) || (c =='\x20'))
  10. int axheard_filter_flag = AXHEARD_PASS;
  11.  
  12. static struct lq *al_create __ARGS((struct iface *ifp,char *addr));
  13. struct lq *al_lookup __ARGS((struct iface *ifp,char *addr,int sort));
  14. static struct ld *ad_lookup __ARGS((struct iface *ifp,char *addr,int sort));
  15. static struct ld *ad_create __ARGS((struct iface *ifp,char *addr));
  16.  
  17. struct ld *Ld;
  18. struct lq *Lq;
  19.  
  20. /* Log the source address of an incoming packet */
  21. void
  22. logsrc(ifp,addr)
  23. struct iface *ifp;
  24. char *addr;
  25. {
  26.     register struct lq *lp;
  27.  
  28.     if(addreq(addr,ifp->hwaddr))
  29.         return;    /* Don't log our own packets if we hear them */
  30.  
  31.     if(axheard_filter_flag & AXHEARD_NOSRC)
  32.         return;
  33.     {
  34.         register unsigned char c;
  35.         register int i = 0;
  36.         while(i < AXALEN-1){
  37.             c = *(addr+i);
  38.             c >>= 1;
  39.             if(!iscallsign(c))
  40.                 return;
  41.             i++;
  42.         }
  43.     }
  44.     
  45.     if((lp = al_lookup(ifp,addr,1)) == NULLLQ)
  46.          if((lp = al_create(ifp,addr)) == NULLLQ)
  47.             return;
  48.     lp->currxcnt++;
  49.     lp->time = Clock;
  50. }
  51. /* Log the destination address of an incoming packet */
  52. void
  53. logdest(ifp,addr)
  54. struct iface *ifp;
  55. char *addr;
  56. {
  57.     register struct ld *lp;
  58.  
  59.     if(axheard_filter_flag & AXHEARD_NODST)
  60.         return;
  61.     {
  62.         register unsigned char c;
  63.         register int i = 0;
  64.         while(i < AXALEN-1){
  65.             c = *(addr+i);
  66.             c >>= 1;
  67.             if(!iscallsign(c))
  68.                 return;
  69.             i++;
  70.         }
  71.     }
  72.     
  73.     if((lp = ad_lookup(ifp,addr,1)) == NULLLD)
  74.         if((lp = ad_create(ifp,addr)) == NULLLD)
  75.             return;
  76.     lp->currxcnt++;
  77.     lp->time = Clock;
  78. }
  79.  
  80. struct lq *al_lookup(ifp,addr,sort)
  81. struct iface *ifp;
  82. char *addr;
  83. int sort;
  84. {
  85.     register struct lq *lp;
  86.     struct lq *lplast = NULLLQ;
  87.  
  88.     for(lp = Lq;lp != NULLLQ;lplast = lp,lp = lp->next){
  89.         if(addreq(lp->addr,addr) && lp->iface == ifp){
  90.             if(sort && lplast != NULLLQ){
  91.                 /* Move entry to top of list */
  92.                 lplast->next = lp->next;
  93.                 lp->next = Lq;
  94.                 Lq = lp;
  95.             }
  96.             return lp;
  97.         }
  98.     }
  99.     return NULLLQ;
  100. }
  101.  
  102. /* Create a new entry in the AX.25 link table */
  103. static struct lq *al_create(ifp,addr)
  104. struct iface *ifp;
  105. char *addr;
  106. {
  107.     register struct lq *lp;
  108.  
  109.     lp = (struct lq *)callocw(1,sizeof(struct lq));
  110.     memcpy(lp->addr,addr,AXALEN);
  111.     lp->next = Lq;
  112.     Lq = lp;
  113.     lp->iface = ifp;
  114.  
  115.     return lp;
  116. }
  117. /* Look up an entry in the destination database */
  118. static struct ld *ad_lookup(ifp,addr,sort)
  119. struct iface *ifp;
  120. char *addr;
  121. int sort;
  122. {
  123.     register struct ld *lp;
  124.     struct ld *lplast = NULLLD;
  125.  
  126.     for(lp = Ld;lp != NULLLD;lplast = lp,lp = lp->next){
  127.         if((lp->iface == ifp) && addreq(lp->addr,addr)){
  128.             if(sort && lplast != NULLLD){
  129.                 /* Move entry to top of list */
  130.                 lplast->next = lp->next;
  131.                 lp->next = Ld;
  132.                 Ld = lp;
  133.             }
  134.             return lp;
  135.         }
  136.     }
  137.     return NULLLD;
  138. }
  139. /* Create a new entry in the destination database */
  140. static struct ld *ad_create(ifp,addr)
  141. struct iface *ifp;
  142. char *addr;
  143. {
  144.     register struct ld *lp;
  145.  
  146.     lp = (struct ld *)callocw(1,sizeof(struct ld));
  147.     memcpy(lp->addr,addr,AXALEN);
  148.     lp->next = Ld;
  149.     Ld = lp;
  150.     lp->iface = ifp;
  151.  
  152.     return lp;
  153. }
  154.  
  155.